package com.cloudptt.api.models.msg;



import java.util.HashMap;
import java.util.Map;

import com.cloudptt.api.product.log.Log;

/**
 * SIP消息扩展部分信息
 * @author TP
 *
 */
public class SysNotifyBodyInfo 
{
	private final static String THIS_FILE = "SysNotifyBodyInfo";

	public static final String Type_Desc_Addr_Update= "addr_update";
	public static final int Type_Addr_Update = 1;

	
	public final static String DefauleValue = "";
	public final static String Key_Result = "result";
	public final static String Key_Group = "group_id";
	
	private String typeStr = null;
	private Map<String,String> valueMap = null;

	
	public SysNotifyBodyInfo(String extStr)
	{
		Log.d(THIS_FILE, "SysNotifyBodyInfo extStr = " + extStr);
		extStr = extStr.trim();
		String[] strArr = extStr.split(";");
		valueMap = new HashMap<String,String>();
		for(int i = 0; i < strArr.length; i++)
		{
			String value = strArr[i];
			if(!value.contains("="))
			{
				this.typeStr = strArr[i].trim();
			}
			else
			{
				String[] valueArr = value.split("=");
				if(valueArr.length == 2)
				{
					if(valueArr[0] != null
							&& valueArr[1] != null)
					{
						valueMap.put(valueArr[0].trim(), valueArr[1].trim());
					}
				}
			}
		}
	}
	
	public int getType()
	{
		if(Type_Desc_Addr_Update.equals(typeStr))
		{
			return Type_Addr_Update;
		}
		return Type_Addr_Update;
	}
	
	public boolean getResult()
	{
		String val = getValue(Key_Result);
		if(val != null
				&& val.equals("suc"))
		{
			return true;
		}
		return false;
	}
	
	public String getValue(String key)
	{
		if(key == null
				|| key.equals(""))
		{
			return DefauleValue;
		}
		
		String value = valueMap.get(key);
		if( value != null ) {
			return value;
		}
		
		return DefauleValue;
	}
	
	public String toString()
	{
		StringBuffer strBuf = new StringBuffer();
		strBuf.append(typeStr).append(";");
		strBuf.append(valueMap);
		return strBuf.toString();
	}
}
